package com.krtech.wecard.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.krtech.wecard.framework.exception.BusinessException;
import com.krtech.wecard.module.sys.entity.OrcodeFreezeList;
import com.krtech.wecard.module.sys.service.OrcodeFreezeListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.krtech.wecard.module.sys.entity.OrcodeLog;
import java.util.List;
import com.krtech.wecard.module.sys.mapper.OrcodeLogMapper;
import com.krtech.wecard.module.sys.service.OrcodeLogService;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrcodeLogServiceImpl extends ServiceImpl<OrcodeLogMapper, OrcodeLog> implements OrcodeLogService {

    @Autowired
    private OrcodeFreezeListService freezeListService;


    @Override
    public int updateBatch(List<OrcodeLog> list) {
        return baseMapper.updateBatch(list);
    }

    @Override
    public int batchInsert(List<OrcodeLog> list) {
        return baseMapper.batchInsert(list);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean unfreeze(String code) {

        //判断当前冻结名单是否有这个人
        int count = freezeListService.count(new QueryWrapper<OrcodeFreezeList>().eq(OrcodeFreezeList.COL_CODE, code));
        if (count <= 0){
            throw new BusinessException("该用户未被冻结");
        }
        this.remove(new QueryWrapper<OrcodeLog>().eq(OrcodeLog.COL_CODE,code));

        return freezeListService.remove(new QueryWrapper<OrcodeFreezeList>().eq(OrcodeFreezeList.COL_CODE,code));
    }
}




